using System.Globalization;
using System.Windows.Data;
using MiniTheme.Ui.Enums;

namespace MiniTheme.Ui.Converters;

// 将图标枚举转换为Unicode字符的转换器
public class IconToUnicodeConverter : IValueConverter
{
    // 枚举到Unicode的映射字典
    private static readonly Dictionary<IconType, int> IconMap = new()
    {
        { IconType.None, 0 },
        { IconType.DownLoad, 0xe608 },
        { IconType.Refresh, 0xe64c },
        { IconType.Share, 0xe619 },
        { IconType.NewChat, 0xe656 },
        { IconType.Setting, 0xe601 },
        { IconType.Search, 0xe643 },
        { IconType.Mask, 0xe600 },
        { IconType.Home, 0xe751 }
    };
    public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
    {
        if (value is IconType iconType && iconType != IconType.None)
        {
            if (IconMap.TryGetValue(iconType, out var unicodeValue))
            {
                //将一个 32位的Unicode码点（一个整数）转换为它对应的字符串（string）
                return char.ConvertFromUtf32(unicodeValue);
            }
        }
        return string.Empty;
    }
    public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
    {
        throw new NotImplementedException();
    }
}
